package com.itheima.innerclass;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Test1 {

    public static void main(String[] args) {
        //创建窗口对象，添加按钮，绑定按钮事件
        JFrame win = new JFrame("窗口");
        win.setSize(400, 400);
        win.setVisible(true);
        win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel panel = new JPanel();
        win.add(panel);
        JButton btn = new JButton("按钮");
        panel.add(btn);
        //使用匿名内部类
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("按钮被点击了");
            }
        });
        btn.addActionListener(e -> {
            System.out.println("按钮被点击了");
        });
        btn.addActionListener(e -> System.out.println("按钮被点击了"));

    }
}
